#include "Signature.h"

/**
 *  @fn	Signature::Signature(void)
 * 
 *  @brief	Default constructor. 
 * 
 *  @author	Nikola Novak
 *  @date	9/21/2009
 */
Signature::Signature(const SyntaxTreeNode &syntaxNode, int id, ValueType *envelopingType) {
	returnType = new ValueType(id);
	int argNodeNum = 0;
	if (syntaxNode.Production == Gr_ConstructorDefinition__ConstrMod_NAME_spLPar_Parameters_spRPar_ConstrInherit_ConstrBody) {
		ctor = true;
		// ToDo: u svaki class staviti ValueType koji predstavlja tip kojeg ta klasa definira,
		//       izvaditi preko parent->getEnvelopingType() i proslijediti u ovaj konstruktor.
		//       getEnvelopingType() nek vraca null ako ne postoji klasa u kojoj je sadrzana metoda
		if (envelopingType == NULL) {
			// ToDo: greska!
			return;
		} else {
			returnType = new ValueType(*envelopingType);
			returnType->setID(id);
		}
		name = CompilerData->Units->GetLexicUnitString(&CompilerData->Units->GetLexicUnit(syntaxNode.Nodes->GetData(1)->LexUnitID));
		argNodeNum = 3;
	} else if (syntaxNode.Production == Gr_MethodDefinition__MethodMods_StartProcess_DataType_NAME_spLPar_Parameters_spRPar_MethodBodyDecl) {
		ctor = false;
	 returnType->setType(syntaxNode.Nodes->GetData(2));
	 name = CompilerData->Units->GetLexicUnitString(&CompilerData->Units->GetLexicUnit(syntaxNode.Nodes->GetData(3)->LexUnitID));
		argNodeNum = 5;
	} else if (syntaxNode.Production == Gr_MethodDefinition__MethodMods_numeric_NumericMod_DataType_NAME_spLPar_Parameters_spRPar_spLCBrac_InfBegin_ValuePairs_InfEnd_spRCBrac) {
		argNodeNum = 6;
	} else {
		// ToDo: greska!
		return;
	}
	SyntaxTreeNode *argNode = syntaxNode.Nodes->GetData(argNodeNum);
	for (int x = 0; x < argNode->Nodes->GetCount(); ++x) {
		//SyntaxTreeNode *curArgument = argNode->Nodes->GetData(x);
		//std::string curArgName = CompilerData->Units->GetLexicUnitString(&CompilerData->Units->GetLexicUnit(curArgument->Nodes->GetData(1)->LexUnitID));
		//SyntaxTreeNode *curArgType = curArgument->Nodes->GetData(0);
		//ValueType *curValueType = new ValueType(-1);
		//curValueType->setType(curArgType);
		//arguments.push_back(curValueType);
	}
}
/**
 *  @fn	ValueType& Signature::getReturnType(void)
 * 
 *  @brief	Gets the return type. 
 * 
 *  @author	Nikola Novak
 *  @date	9/21/2009
 * 
 *  @return	The return type.
 */
ValueType &Signature::getReturnType(void) {
	return *returnType;
}
/**
 *  @fn	std::map<std::string,ValueType*> Signature::getArguments(void)
 * 
 *  @brief	Gets the arguments.
 * 
 *  @author	Nikola Novak
 *  @date	9/21/2009
 * 
 *  @return	null if it fails, else the arguments.
 */
std::vector<ValueType *> Signature::getArguments(void) {
	return arguments;
}
/**
 *  @fn	int Signature::getArgumentNumber(void)
 * 
 *  @brief	Gets the argument number. 
 * 
 *  @author	Nikola Novak
 *  @date	9/21/2009
 * 
 *  @return	The argument number.
 */
int Signature::getArgumentNumber(void) {
	return arguments.size();
}
/**
 *  @fn	ValueType& Signature::getArgumentType(int argumentNumber)
 * 
 *  @brief	Gets an argument type. 
 * 
 *  @author	Nikola Novak
 *  @date	9/21/2009
 * 
 *  @param	argumentNumber	The argument number.
 * 
 *  @return	The argument type.
 */
ValueType &Signature::getArgumentType(int argumentNumber) {
	return *arguments[argumentNumber % arguments.size()];
}
/**
 *  @fn	std::string Signature::getName(void)
 * 
 *  @brief	Gets the name. 
 * 
 *  @author	Nikola Novak
 *  @date	9/21/2009
 * 
 *  @return	The name.
 */
std::string Signature::getName(void) {
	return name;
}
/**
 *  @fn	bool Signature::operator==(const Signature &sig) const
 * 
 *  @brief	Equality operator. 
 * 
 *  @author	Nikola Novak
 *  @date	9/21/2009
 * 
 *  @param	sig	The sig.
 * 
 *  @return	true if the parameters are considered equivalent.
 */
bool Signature::operator==(const Signature &sig) const {
	
	return(false);
}
/**
 *  @fn	bool Signature::operator!=(const Signature &sig) const
 * 
 *  @brief	Inequality operator. 
 * 
 *  @author	Nikola Novak
 *  @date	9/21/2009
 * 
 *  @param	sig	The sig.
 * 
 *  @return	true if the parameters are not considered equivalent.
 */
bool Signature::operator!=(const Signature &sig) const {
	return !operator==(sig);
}